<?php
/**
 * Created by PhpStorm.
 * User: JackWang
 * Date: 2022/4/28
 * Time: 9:34
 */

declare(strict_types=1);
require_once 'C:/phpstudy_pro/WWW/test/phpuint/CsvFileIterator.php';

use PHPUnit\Framework\TestCase;

final class DataTest extends TestCase
{
    /**
     * 可以使用多个数据供给器
     * @dataProvider additionProvider1
     * @dataProvider additionProvider2
     * @dataProvider additionProvider
     * @param int $a
     * @param int $b
     * @param int $c
     */
    public function testAdd(int $a, int $b, int $c): void
    {
        $this->assertSame($c, $a + $b);
    }

    public function additionProvider1(): array
    {
        return [
            [0, 0, 0],
            [0, 1, 1],
            [1, 0, 1],
            [1, 1, 2]
        ];
    }

    /**
     * 可以带上键名，使用默认的键名不好排查
     * @return array
     */
    public function additionProvider2(): array
    {
        return [
            'arr1' => [0, 0, 0],
            'arr2' => [0, 1, 1],
            'arr3' => [1, 0, 1],
            'arr4' => [1, 1, 2]
        ];
    }

    public function additionProvider(): array
    {
        //读取data.csv文件
        $data = new CsvFileIterator('nac.csv');
        $data1 = [];
        //将返回的对象文件转换为数组
        foreach ($data as $k => $v) {
            $data1[$k] = $v;
            foreach ($v as $kk => $vv) {
                //二维数组的值必须为int类型
                $data1[$k][$kk] = intval($vv);
            }
        }
        //返回int数组
        return $data1;
    }
}


